$(function () {
    $(".home-tabBar > .home-tabBar-item").eq(3).click();
});

$(".home-tabBar > .home-tabBar-item").click(function () {
    if (!$(this).find('div').hasClass('home-tabBar-text')) {
        $(this).find('div').addClass('home-tabBar-text');
        $(this).siblings().find('div').removeClass('home-tabBar-text');
        $(this).find('.selection').show().siblings('.unchecked').hide();
        $(this).siblings().find('.unchecked').show().siblings('.selection').hide();
        if ($(this).find('div').html() == "预约") {
            window.location.href = Feng.ctxPath + "/receptionPatientsCentral/appointment_index";
        } else if ($(this).find('div').html() == "首页") {
            window.location.href = Feng.ctxPath + "/weixin/index";
        }
    }
});

var seletsex = $('#isex').val();
if ($('#id').val() != "") {
    $("#sex option[value=" + seletsex + "]").attr("selected", "selected");
}

function personalCentres() {
    window.location.href = Feng.ctxPath + "/appMy/personalCentres";
}

function appWeblogout() {
    window.location.href = Feng.ctxPath + "/appMy/logout";
}

function updatePassWord() {
    window.location.href = Feng.ctxPath + "/appMy/toUpdatePassWord";
}

function updatePersonal() {
    window.location.href = Feng.ctxPath + "/appMy/updatePersonal";
}

/**
 * 提交資料
 */
editSubmit = function () {
    var sex = $('#sex').val();
    var email = $('#email').val();
    var phone = $('#phone').val();
    $.ajax({
        url: Feng.ctxPath + "/appMy/editSubmit",
        type: "post",
        data: {
            sex: sex,
            email: email,
            phone: phone
        },
        success: function (data) {
            Feng.success('操作成功!');
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
};

/**
 * 提交密碼
 */
onSubmit = function () {
    var passWord = $('#passWord').val();
    var newPassWord = $('#newPassWord').val();
    var reNewPassWord = $('#reNewPassWord').val();
    if (newPassWord != reNewPassWord) {
        alert("新密码输入不一致！");
    } else if (newPassWord == null || newPassWord == "") {
        alert("新密码不为空！");
    } else if (newPassWord.length > 20) {
        alert("新密码長度不大于20！");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/appMy/updatePassWord",
            type: "post",
            data: {
                "passWord": passWord,
                "newPassWord": newPassWord
            },
            dataType: "json",
            success: function (data) {
                if (data == '0') {
                    alert("密码修改成功！");
                    window.location.href = Feng.ctxPath + "/appMy/logout";
                } else {
                    alert("原密码错误，请重新输入原密码！");
                }
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};